<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./css/style.css">
    <link rel="stylesheet" href="./css/base.css">
    <link rel="stylesheet" href="./css/normalize.css">
    <link rel="stylesheet" href="./css/swiper-bundle.min.css">

    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./js/swiper-bundle.min.js"></script>
    <script src="./js/common.js"></script>

    <script>
        function checkPro(){
            var ids = document.getElementsByName("ids[]");
            var bool = false;
            for(var i=0;i<ids.length;i++){
                if(ids[i].checked==true){
                    bool=true;
                }
            }
            if(!bool){
                alert("请选择需要购买的商品");
                return false;
            }else{
                return true;
            }
        }

    </script>
    <style>
        .pnums i{
            font-size: 20px;
            display: inline-block;
            width: 20px;
            border: 1px solid #000;
            text-align: center;
            background-color: #f0f0f0;
            height: 33px;
            cursor: pointer;
        }
        /*谷歌*/
        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }
        /*火狐*/
        input[type="number"] {
            -moz-appearance: textfield;
        }
    </style>


</head>
<body>
<!---------------------------------header----------------------->
<iframe src="./header.php" frameborder="0" name="header_iframe" width="100%" scrolling="no"></iframe>

<main>
    <div class="wrapper">
        <form action="./addOrder.php" method="post">
            <table width="100%">
                <tr>
                    <th width="10%" align="center">全选</th>
                    <th width="35%" align="left">商品名称</th>
                    <th width="20%" align="center">商品数量</th>
                    <th width="15%" align="center">商品单价</th>
                    <th width="20%" align="center">商品总价</th>
                </tr>
                <?php if(is_array($proResults)):foreach($proResults as $k=>$pro):?>
                <tr>
                    <input type="hidden" id="pnum<?=$k?>" value="<?=$pro['pnum']?>">
                    <td width="10%"  align="center">
                        <input type="checkbox" name="ids[]" value="<?=$pro['id']?>">
                    </td>
                    <td width="35%"><?=$pro['name']?></td>
                    <td width="20%" align="center" class="pnums">
                        <i id="prep<?=$k?>" onclick="changeNum('-','<?=$k?>')" >-</i>
                        <input type="number" value="<?=$pro['buynum']?>" id="num<?=$k?>" style="width: 50px;" onkeyup="changeNum1('<?=$k?>')" name="buyNum[]">
                        <i id="add<?=$k?>" onclick="changeNum('+','<?=$k?>')">+</i>
                    </td>
                    <td width="15%" align="center">￥<?=$pro['price']?></td>
                    <td width="20%" align="center">
                        <input type="hidden" value="<?=$pro['price']?>" id="price<?=$k?>" name="price[]">
                        ￥
                    <script>
                        var count = document.getElementById('num<?=$k?>').value;
                        var price = document.getElementById('price<?=$k?>').value;
                        document.write(count*price);
                    </script>
                    </td>
                </tr>
                <?php endforeach;endif;?>
                <tr>
                    <td colspan="5" class="ri-but">
                        <h5 style="color: red;"><?=setMsg($msg)?></h5>
                        <button type="submit" class="right-but" onclick="javascript:return checkPro()">立即购买</button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</main>

<iframe src="./footer.php" name="footer_iframe" width="100%" frameborder="0" scrolling="no"></iframe>





</body>
</html>